package com.study.reflect.example2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author HBZ
 * @Date 2020/7/29 23:34
 * @Description
 */
public class MyInvocationHandler implements InvocationHandler {

    private Object target;

    public void setTarget(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        DogEnhance enhance = new DogEnhance();
        enhance.method1();
        // 以target为主调来执行method方法
        Object result = method.invoke(target, args);
        enhance.method2();
        return result;
    }
}
